1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.ListView;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.ListBase;
31 private import gtk.ListItemFactory;
32 private import gtk.SelectionModelIF;
33 private import gtk.Widget;
34 private import gtk.c.functions;
35 public  import gtk.c.types;
36 private import std.algorithm;
37 
38 
39 /**
40  * `GtkListView` presents a large dynamic list of items.
41  * 
42  * `GtkListView` uses its factory to generate one row widget for each visible
43  * item and shows them in a linear display, either vertically or horizontally.
44  * 
45  * The [property@Gtk.ListView:show-separators] property offers a simple way to
46  * display separators between the rows.
47  * 
48  * `GtkListView` allows the user to select items according to the selection
49  * characteristics of the model. For models that allow multiple selected items,
50  * it is possible to turn on _rubberband selection_, using
51  * [property@Gtk.ListView:enable-rubberband].
52  * 
53  * If you need multiple columns with headers, see [class@Gtk.ColumnView].
54  * 
55  * To learn more about the list widget framework, see the
56  * [overview](section-list-widget.html).
57  * 
58  * An example of using `GtkListView`:
59  * ```c
60  * static void
61  * setup_listitem_cb (GtkListItemFactory *factory,
62  * GtkListItem        *list_item)
63  * {
64  * GtkWidget *image;
65  * 
66  * image = gtk_image_new ();
67  * gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
68  * gtk_list_item_set_child (list_item, image);
69  * }
70  * 
71  * static void
72  * bind_listitem_cb (GtkListItemFactory *factory,
73  * GtkListItem        *list_item)
74  * {
75  * GtkWidget *image;
76  * GAppInfo *app_info;
77  * 
78  * image = gtk_list_item_get_child (list_item);
79  * app_info = gtk_list_item_get_item (list_item);
80  * gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
81  * }
82  * 
83  * static void
84  * activate_cb (GtkListView  *list,
85  * guint         position,
86  * gpointer      unused)
87  * {
88  * GAppInfo *app_info;
89  * 
90  * app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
91  * g_app_info_launch (app_info, NULL, NULL, NULL);
92  * g_object_unref (app_info);
93  * }
94  * 
95  * ...
96  * 
97  * model = create_application_list ();
98  * 
99  * factory = gtk_signal_list_item_factory_new ();
100  * g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
101  * g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
102  * 
103  * list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
104  * 
105  * g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
106  * 
107  * gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
108  * ```
109  * 
110  * # CSS nodes
111  * 
112  * ```
113  * listview[.separators][.rich-list][.navigation-sidebar][.data-table]
114  * ├── row[.activatable]
115  * │
116  * ├── row[.activatable]
117  * │
118  * ┊
119  * ╰── [rubberband]
120  * ```
121  * 
122  * `GtkListView` uses a single CSS node named `listview`. It may carry the
123  * `.separators` style class, when [property@Gtk.ListView:show-separators]
124  * property is set. Each child widget uses a single CSS node named `row`.
125  * If the [property@Gtk.ListItem:activatable] property is set, the
126  * corresponding row will have the `.activatable` style class. For
127  * rubberband selection, a node with name `rubberband` is used.
128  * 
129  * The main listview node may also carry style classes to select
130  * the style of [list presentation](ListContainers.html#list-styles):
131  * .rich-list, .navigation-sidebar or .data-table.
132  * 
133  * # Accessibility
134  * 
135  * `GtkListView` uses the %GTK_ACCESSIBLE_ROLE_LIST role, and the list
136  * items use the %GTK_ACCESSIBLE_ROLE_LIST_ITEM role.
137  */
138 public class ListView : ListBase
139 {
140 	/** the main Gtk struct */
141 	protected GtkListView* gtkListView;
142 
143 	/** Get the main Gtk struct */
144 	public GtkListView* getListViewStruct(bool transferOwnership = false)
145 	{
146 		if (transferOwnership)
147 			ownedRef = false;
148 		return gtkListView;
149 	}
150 
151 	/** the main Gtk struct as a void* */
152 	protected override void* getStruct()
153 	{
154 		return cast(void*)gtkListView;
155 	}
156 
157 	/**
158 	 * Sets our main struct and passes it to the parent class.
159 	 */
160 	public this (GtkListView* gtkListView, bool ownedRef = false)
161 	{
162 		this.gtkListView = gtkListView;
163 		super(cast(GtkListBase*)gtkListView, ownedRef);
164 	}
165 
166 
167 	/** */
168 	public static GType getType()
169 	{
170 		return gtk_list_view_get_type();
171 	}
172 
173 	/**
174 	 * Creates a new `GtkListView` that uses the given @factory for
175 	 * mapping items to widgets.
176 	 *
177 	 * The function takes ownership of the
178 	 * arguments, so you can write code like
179 	 * ```c
180 	 * list_view = gtk_list_view_new (create_model (),
181 	 * gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
182 	 * ```
183 	 *
184 	 * Params:
185 	 *     model = the model to use
186 	 *     factory = The factory to populate items with
187 	 *
188 	 * Returns: a new `GtkListView` using the given @model and @factory
189 	 *
190 	 * Throws: ConstructionException GTK+ fails to create the object.
191 	 */
192 	public this(SelectionModelIF model, ListItemFactory factory)
193 	{
194 		auto __p = gtk_list_view_new((model is null) ? null : model.getSelectionModelStruct(), (factory is null) ? null : factory.getListItemFactoryStruct());
195 
196 		if(__p is null)
197 		{
198 			throw new ConstructionException("null returned by new");
199 		}
200 
201 		this(cast(GtkListView*) __p);
202 	}
203 
204 	/**
205 	 * Returns whether rows can be selected by dragging with the mouse.
206 	 *
207 	 * Returns: %TRUE if rubberband selection is enabled
208 	 */
209 	public bool getEnableRubberband()
210 	{
211 		return gtk_list_view_get_enable_rubberband(gtkListView) != 0;
212 	}
213 
214 	/**
215 	 * Gets the factory that's currently used to populate list items.
216 	 *
217 	 * Returns: The factory in use
218 	 */
219 	public ListItemFactory getFactory()
220 	{
221 		auto __p = gtk_list_view_get_factory(gtkListView);
222 
223 		if(__p is null)
224 		{
225 			return null;
226 		}
227 
228 		return ObjectG.getDObject!(ListItemFactory)(cast(GtkListItemFactory*) __p);
229 	}
230 
231 	/**
232 	 * Gets the model that's currently used to read the items displayed.
233 	 *
234 	 * Returns: The model in use
235 	 */
236 	public SelectionModelIF getModel()
237 	{
238 		auto __p = gtk_list_view_get_model(gtkListView);
239 
240 		if(__p is null)
241 		{
242 			return null;
243 		}
244 
245 		return ObjectG.getDObject!(SelectionModelIF)(cast(GtkSelectionModel*) __p);
246 	}
247 
248 	/**
249 	 * Returns whether the list box should show separators
250 	 * between rows.
251 	 *
252 	 * Returns: %TRUE if the list box shows separators
253 	 */
254 	public bool getShowSeparators()
255 	{
256 		return gtk_list_view_get_show_separators(gtkListView) != 0;
257 	}
258 
259 	/**
260 	 * Returns whether rows will be activated on single click and
261 	 * selected on hover.
262 	 *
263 	 * Returns: %TRUE if rows are activated on single click
264 	 */
265 	public bool getSingleClickActivate()
266 	{
267 		return gtk_list_view_get_single_click_activate(gtkListView) != 0;
268 	}
269 
270 	/**
271 	 * Sets whether selections can be changed by dragging with the mouse.
272 	 *
273 	 * Params:
274 	 *     enableRubberband = %TRUE to enable rubberband selection
275 	 */
276 	public void setEnableRubberband(bool enableRubberband)
277 	{
278 		gtk_list_view_set_enable_rubberband(gtkListView, enableRubberband);
279 	}
280 
281 	/**
282 	 * Sets the `GtkListItemFactory` to use for populating list items.
283 	 *
284 	 * Params:
285 	 *     factory = the factory to use
286 	 */
287 	public void setFactory(ListItemFactory factory)
288 	{
289 		gtk_list_view_set_factory(gtkListView, (factory is null) ? null : factory.getListItemFactoryStruct());
290 	}
291 
292 	/**
293 	 * Sets the model to use.
294 	 *
295 	 * This must be a [iface@Gtk.SelectionModel] to use.
296 	 *
297 	 * Params:
298 	 *     model = the model to use
299 	 */
300 	public void setModel(SelectionModelIF model)
301 	{
302 		gtk_list_view_set_model(gtkListView, (model is null) ? null : model.getSelectionModelStruct());
303 	}
304 
305 	/**
306 	 * Sets whether the list box should show separators
307 	 * between rows.
308 	 *
309 	 * Params:
310 	 *     showSeparators = %TRUE to show separators
311 	 */
312 	public void setShowSeparators(bool showSeparators)
313 	{
314 		gtk_list_view_set_show_separators(gtkListView, showSeparators);
315 	}
316 
317 	/**
318 	 * Sets whether rows should be activated on single click and
319 	 * selected on hover.
320 	 *
321 	 * Params:
322 	 *     singleClickActivate = %TRUE to activate items on single click
323 	 */
324 	public void setSingleClickActivate(bool singleClickActivate)
325 	{
326 		gtk_list_view_set_single_click_activate(gtkListView, singleClickActivate);
327 	}
328 
329 	/**
330 	 * Emitted when a row has been activated by the user,
331 	 * usually via activating the GtkListView|list.activate-item action.
332 	 *
333 	 * This allows for a convenient way to handle activation in a listview.
334 	 * See [method@Gtk.ListItem.set_activatable] for details on how to use
335 	 * this signal.
336 	 *
337 	 * Params:
338 	 *     position = position of item to activate
339 	 */
340 	gulong addOnActivate(void delegate(uint, ListView) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
341 	{
342 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
343 	}
344 }